# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html

import MySQLdb
import datetime
import time


class HorsveisionPipeline(object):
    def process_item(self, item, spider):
        return item


class MysqlPipeline(object):
    def __init__(self):
        self.conn = MySQLdb.connect('localhost', 'root', '698a80e4212ba38f', 'toujiao', charset='utf8', use_unicode=True)
        self.cursor = self.conn.cursor()

    def process_item(self, item, spider):
        now_time = int(time.time())
        insert_sql = """
              insert into spider_content(title,cover_img,content,source,send_time,create_time)values(%s,%s,%s,%s,%s,%s)
        """
        self.cursor.execute(insert_sql,
                            (item['title'], item['cover_img'], item['content'], item['source'], item['send_time'],
                             now_time))

        self.conn.commit()
